const mysqlConnection = require('./db/index')
console.log('mysqlConnection', mysqlConnection)
const onSelectOnlyUser = function (params) {
  return new Promise(function (resolve, reject) {
    let selectSql =
      "SELECT userid,username,email,DATE_FORMAT(createtime,'%Y-%m-%d %h:%i:%s') AS createtime FROM user WHERE email = ? AND password = ? "
    let selectSqlParams = [params.email, params.password]
    mysqlConnection.query(selectSql, selectSqlParams, function (err, result) {
      if (err) {
        console.log('[INSERT ERROR] - ', err.message)
        reject(err)
        return
      }

      console.log('--------------------------SELECT----------------------------')
      //console.log('INSERT ID:',result.insertId);
      console.log('SELECT ID:', result)
      console.log('-----------------------------------------------------------------\n\n')
      resolve(result)
    })
  })
}

module.exports = {
  onSelectOnlyUser
}
